package pe.com.pgn.consolidadorventas.servidorestacion.ws.security;

import java.io.IOException;

import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;

import pe.com.pgn.consolidadorventas.servidorestacion.ws.security.service.WsSeguridadService;

import com.sun.xml.wss.impl.callback.PasswordValidationCallback;

public class SecurityEnvironmentHandler implements CallbackHandler {

	WsSeguridadService wsSeguridadService;
	
	public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
        for (Callback callback : callbacks) {
            if (callback instanceof PasswordValidationCallback) {
                PasswordValidationCallback passwordValidationCallback = (PasswordValidationCallback) callback;
                passwordValidationCallback.setValidator(new PlainTextPasswordValidator(wsSeguridadService));
            } else {
                throw new UnsupportedCallbackException(callback);
            }
        }
    }
	
	public SecurityEnvironmentHandler(WsSeguridadService wsSeguridadService){
		this.wsSeguridadService=wsSeguridadService;
	}
	

}